## Common stuff used in Makefiles of extensions  -*-mode: Makefile-*-
##

SHELL       = @SHELL@
prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = @bindir@
libdir      = @libdir@
datadir     = @datadir@
datarootdir = @datarootdir@
VPATH       = $(srcdir)
GAUCHE_VERSION = @GAUCHE_VERSION@
GAUCHE_ABI_VERSION = @GAUCHE_ABI_VERSION@
BUILD       = @build@
HOST        = @host@

# These may be overridden by make invocators
DESTDIR      =
CC           = @CC@
AR           = @AR@
LOCAL_LFLAGS = @LOCAL_LIB@
LIBS         = $(XLIBS) @LIBS@
CFLAGS       = @CFLAGS@ @SHLIB_SO_CFLAGS@ $(XCFLAGS)
CPPFLAGS     = @CPPFLAGS@ $(XCPPFLAGS)
LDFLAGS      = $(LOCAL_LFLAGS) $(XLDFLAGS) @SHLIB_SO_LDFLAGS@
BUILD_GOSH_FLAGS =

# These are set by configure
DEFS     = @DEFS@
OPTFLAGS = @OPTFLAGS@
INCLUDES = -I. -I$(srcdir) -I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/gc/include @LOCAL_INC@ $(EXTRA_INCLUDES)
OBJEXT   = @OBJEXT@
EXEEXT   = @EXEEXT@
SOEXT    = @SHLIB_SO_SUFFIX@
BUILD_GOSH = "@BUILD_GOSH@" `cat $(top_builddir)/src/features.flags`

# Main definition of compilation commands
COMPILE   = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(OPTFLAGS)
CCLD      = $(CC)
LINK      = $(CCLD) $(CFLAGS) $(LDFLAGS)
MODLINK   = $(CCLD) $(CFLAGS) $(LDFLAGS)

@CROSS_COMPILING_no@GOSH           = "$(top_builddir)/src/gosh" -ftest
@CROSS_COMPILING_yes@GOSH           = $(BUILD_GOSH) $(BUILD_GOSH_FLAGS)
GAUCHE_INSTALL = $(GOSH) "$(top_srcdir)/src/gauche-install.in" -C
PRECOMP        = $(GOSH) "$(top_srcdir)/src/precomp"
INSTALL_TYPE   = sys

EXT_LIBGAUCHE  = -L"$(top_builddir)/src" @EXT_LIBGAUCHE@

GAUCHE_INCDIR  = $(DESTDIR)$(libdir)/gauche-$(GAUCHE_ABI_VERSION)/$(GAUCHE_VERSION)/include
GAUCHE_LIBDIR  = $(DESTDIR)$(datadir)/gauche-$(GAUCHE_ABI_VERSION)/$(GAUCHE_VERSION)/lib
GAUCHE_ARCHDIR = $(DESTDIR)$(libdir)/gauche-$(GAUCHE_ABI_VERSION)/$(GAUCHE_VERSION)/$(HOST)

LIB_INSTALL_DIR  = @libdir@
BIN_INSTALL_DIR  = @bindir@
DATA_INSTALL_DIR = @datadir@

CLEANFILES = core *~ test.log test.out $(XCLEANFILES)

TESTRECORD = "$(top_builddir)/test.record"

.SUFFIXES:
.SUFFIXES: .S .c .o .obj .s .stub

.PHONY: default all check install install-check clean distclean \
        maintainer-clean install-std uninstall link unlink list-objects \
	pre-package

.c.obj:
	$(COMPILE) -o `cygpath -w $@` -c `cygpath -w $<`

.c.o:
	$(COMPILE) -o $@ -c $<

.s.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -c $<

.stub.c :
	$(GOSH) "$(top_srcdir)/src/genstub" $<

default : all link

check : all
	@rm -f test.log
	GAUCHE_TEST_RECORD_FILE=$(TESTRECORD) $(GOSH) -I"$(srcdir)" -I. "$(srcdir)/test.scm" > test.log

install-check :
	GAUCHE_TEST_RECORD_FILE=$(TESTRECORD) "${bindir}/gosh" "$(srcdir)/test.scm"

clean : unlink
	rm -rf $(CLEANFILES) *.$(OBJEXT) *.$(SOEXT)

distclean : clean
	rm -rf $(GENERATED)

maintainer-clean : clean
	rm -rf $(GENERATED)

pre-package : $(PRE_PACKAGE_FILES)

install-std : all
	$(GAUCHE_INSTALL) -m 444 -S "$(srcdir)" -T "$(GAUCHE_INCDIR)" $(HDRFILES)
	$(GAUCHE_INSTALL) -m 444 -S "$(srcdir)" -T "$(GAUCHE_LIBDIR)/$(SCM_CATEGORY)" $(SCMFILES)
	$(GAUCHE_INSTALL) -m 555 -T "$(GAUCHE_ARCHDIR)" $(LIBFILES)

uninstall :

link : all
	-$(GOSH) "$(top_srcdir)/ext/xlink" -l -g "$(SCM_CATEGORY)" \
	  -b "$(top_builddir)" -s $(srcdir) $(LIBFILES) $(SCMFILES)

unlink :
	-@$(GOSH) "$(top_srcdir)/ext/xlink" -u -g "$(SCM_CATEGORY)" \
	  -b "$(top_builddir)" -s $(srcdir) $(LIBFILES) $(SCMFILES)

list-objects:
	@if test "X$(OBJECTS)" != X; then \
	   for o in $(OBJECTS); do echo "/// `pwd`/$$o"; done;\
	fi
